var AreaTool=function(option){
	var me = this;
	me.province=option.province;
	me.city=option.city;
	me.town=option.town;
	me.street=option.street;
	$("#"+me.province).change(function(){
		me._selectProvince();
	});
	$("#"+me.city).change(function(){
		me._selectCity();
	});
	$("#"+me.town).change(function(){
		me._selectTown();
	});
	me._init();
};
AreaTool.prototype = {
		_init:function(){
			var me=this;
			var param="";
			var privinceid = $("#" + me.province+"_value").val();
			if(privinceid!=null)
			{
				param+="&areaUtil.provinceid="+privinceid;
			}
			var cityid=$("#"+me.city+"_value").val();
			if(cityid!=null)
			{
				param+="&areaUtil.cityid="+cityid;
			}
			var townid=$("#"+me.town+"_value").val();
			if(townid!=null)
			{
				param+="&areaUtil.townid="+townid;
			}
			var streetid=$("#"+me.street+"_value").val();
			if(streetid!=null)
			{
				param+="&areaUtil.streetid="+streetid;
			}
			$.getJSON("areaUtil_initUtil?data="+new Date()+param,function(data){
				me._refreshProvince(data);
				me._refreshCity(data);
				me._refreshTown(data);
				me._refreshStreet(data);
			})
		},
		_selectProvince:function()
		{
			var me=this;
			var privinceid=$("#"+me.province).val();
			$.getJSON("areaUtil_selectProvince?data="+new Date()+"&areaUtil.provinceid="+privinceid,function(data){
				me._refreshCity(data);
				me._refreshTown(data);
				me._refreshStreet(data);
			})
		},
		_selectCity:function(){
			var me=this;
			var cityid=$("#"+me.city).val();
			$.getJSON("areaUtil_selectCity?data="+new Date()+"&areaUtil.cityid="+cityid,function(data){
				me._refreshTown(data);
				me._refreshStreet(data);
			})
		},
		_selectTown:function(){
			var me=this;
			var townid=$("#"+me.town).val();
			$.getJSON("areaUtil_selectTown?data="+new Date()+"&areaUtil.townid="+townid,function(data){
				me._refreshStreet(data);
			})
		},
		_refreshProvince:function(data){
			var me = this;
			$("#"+me.province).empty();
			$.each(data.areaUtil.provinceList,function(i,item){
				var line='<option value="'+item.pk+'">'+item.name+'</option>';
				$("#"+me.province).append(line);
			});
			$("#"+me.province).val(data.areaUtil.provinceid);
		},
		_refreshCity:function(data){
			var me = this;
			$("#"+me.city).empty();
			$.each(data.areaUtil.cityList,function(i,item){
				var line='<option value="'+item.pk+'">'+item.name+'</option>';
				$("#"+me.city).append(line);
			});
			$("#"+me.city).val(data.areaUtil.cityid);
		},
		_refreshTown:function(data){
			var me = this;
			$("#"+me.town).empty();
			$.each(data.areaUtil.townList,function(i,item){
				var line='<option value="'+item.pk+'">'+item.name+'</option>';
				$("#"+me.town).append(line);
			});
			$("#"+me.town).val(data.areaUtil.townid);
		},
		_refreshStreet:function(data){
			var me = this;
			$("#"+me.street).empty();
			$.each(data.areaUtil.streetList,function(i,item){
				var line='<option value="'+item.pk+'">'+item.name+'</option>';
				$("#"+me.street).append(line);
			});
			$("#"+me.street).val(data.areaUtil.streetid);
		}
}